import * as SettingApi from '@src/api/SettingApi';
import { i18n } from '@src/locales';
import { Message } from 'element-ui'

export async function handleChangeUseDept(params: Record<string, any>, type: string) {
    try {
      const { value = [{}, {}], id } = params 
      const [ { checkedIdArr: checkedIdCreateArr }, { checkedIdArr: checkedIdCheckArr } ] = value
      const reqParams = {
        id,
        writeList: checkedIdCreateArr?.value ?? [],
        readList: checkedIdCheckArr?.value ?? [],
        type
      }
      const { succ = true, status } = await SettingApi.changeEventOrTaskTags(reqParams)
      if(succ) {
        Message.success(i18n.t('common.base.saveSuccess') as unknown as string)
        return succ
      }
    } catch(e) {
      console.error('【fetch SettingApi.changeEventOrTaskTags error】', e)
    }
  }
export async function handleChooseUseDept(typeItem: Record<string, any>, type: string) {
    try {
      const { succ, status, data } = await SettingApi.getTaskTypeItemDetail({ taskTypeId: typeItem.id, type })
      if(succ) {
          const { readList = [], writeList = [] } = data
          const params = {
            id: typeItem.id,
            createChoosedDeptTag: writeList ?? [],
            checkChoosedDeptTag: readList ?? []
          }
        // @ts-ignore
        this.$refs.chooseTeamConfirmDialog.showModal(params)
      }
    } catch(e) {
      console.error('【fetch SettingApi.getTaskTypeItemDetail error】', e)
    }
  }